function truncate(str, maxlength) {
    if (str.length > maxlength) {
        let newStr = str.slice(0, maxlength-1);
        newStr = newStr + `...`;
        return newStr;
    } else {
        return str;
    }
};

alert(truncate(`What I'd like to tell on this topic is:`, 20));

alert(truncate(`Hi everyone!`, 20));